package com.abe.jmcl.android.menu.fragment;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import com.abe.jmcl.R;
import com.abe.jmcl.adapter.MenuCommonAdapter;
import com.abe.jmcl.android.database.GreenDaoActivity;
import com.abe.jmcl.android.retrofit.RetrofitXmlActivity;
import com.abe.jmcl.android.retrofit.ServiceTestActivity;
import com.abe.jmcl.android.share.AndShareActivity;
import com.abe.jmcl.android.share.UMengShowActivity;
import com.abe.jmcl.android.widget.ShowWidgetActivity;
import com.abe.jmcl.android.widget.SlidingMenuActivity;
import com.abe.jmcl.android.widget.panel.PanelMainActivity;
import com.abe.jmcl.android.widget.panel.SlidingUpPanelActivity;
import com.abe.jmcl.entity.BaseMenuEntity;
import com.abe.libui.android.zxing.activity.CaptureActivity;
import com.abeframe.core.base.MVPBaseFragment;
import com.abeframe.core.base.MVPBasePresenter;
import com.abeframe.core.libs.adapter.CommonData;
import com.abeframe.core.utils.EmptyUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class MenuModuleFragment extends MVPBaseFragment implements AdapterView.OnItemClickListener {
    @Override
    protected MVPBasePresenter createPresenter() {
        return null;
    }

    @Override
    protected void init() {

    }

    @Override
    protected int getLayoutResId() {
        return R.layout.fragment_menu_module;
    }

    @Override
    protected void initDatas() {
        initGrid();
        List<CommonData> datas = new ArrayList<>();
        for (int i = 0; i < menus.length; i++) {
            datas.add(new CommonData(MenuCommonAdapter.TYPE_MENU_MODULE, new BaseMenuEntity(menus[i], menuIcons[i])));
        }
        MenuCommonAdapter adapter = new MenuCommonAdapter(getThisContext(), datas);
        gridView.setAdapter(adapter);
    }

    private void initGrid() {
        gridView.setNumColumns(3);
        gridView.setOnItemClickListener(this);
    }

    public MenuModuleFragment() {
    }

    public static MenuModuleFragment newInstance() {
        return new MenuModuleFragment();
    }

    @BindView(R.id.item_grid_common)
    GridView gridView;

    private String[] menus = {"菜单", "社会化", "二维码", "侧滑", "ORM", "retrofit-xml", "系统分享", "PanelLayout", "androidPanel", "接口测试"};
    private int[] menuIcons = {R.drawable.icon_menu_common, R.drawable.icon_menu_common,
            R.drawable.icon_menu_common, R.drawable.icon_menu_common, R.drawable.icon_menu_common,
            R.drawable.icon_menu_common, R.drawable.icon_menu_common, R.drawable.icon_menu_common,
            R.drawable.icon_menu_common, R.drawable.icon_menu_common};

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        if (EmptyUtils.isNotEmpty(getActivity()))
            switch (i) {
                case 0: {
                    startActivity(new Intent(getActivity(), ShowWidgetActivity.class));
                }
                break;
                case 1: {
                    startActivity(new Intent(getActivity(), UMengShowActivity.class));
                }
                break;
                case 2: {
                    startActivity(new Intent(getActivity(), CaptureActivity.class));
                }
                break;
                case 3: {
                    startActivity(new Intent(getActivity(), SlidingMenuActivity.class));
                }
                break;
                case 4: {
                    startActivity(new Intent(getActivity(), GreenDaoActivity.class));
                }
                break;
                case 5: {
                    startActivity(new Intent(getActivity(), RetrofitXmlActivity.class));
                }
                break;
                case 6: {
                    startActivity(new Intent(getActivity(), AndShareActivity.class));
                }
                break;
                case 7: {
                    startActivity(new Intent(getActivity(), PanelMainActivity.class));
                }
                break;
                case 8: {
                    startActivity(new Intent(getActivity(), SlidingUpPanelActivity.class));
                }
                break;
                case 9: {
                    startActivity(new Intent(getActivity(), ServiceTestActivity.class));
                }
                break;
            }
    }
}
